package com.itsm.xkitsm.liferoot.ems;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.itsm.xkitsm.liferoot.R;

/**
 * 
 * @author xiajun	
 * @version1.0
 */
public abstract class BaseContorl {
	
   	  static  AnimationDrawable  animation;
   	  static ProgressDialog progress;
	  public static void doShowDialog(final BaseUI ui,View view,int width,int height){
		  ui.getDialog().setContentView(view,new LayoutParams(width,LayoutParams.WRAP_CONTENT) );
		  ui.getDialog().show();
	   }
	  
	  public static void doShowToask(final Context context,int flag,int message){
		   LayoutInflater inflater=LayoutInflater.from(context);
		   View toaskView=null;
		   if(flag==0){
			   toaskView=inflater.inflate(R.layout.error_toask, null);
		   }else{
			   toaskView=inflater.inflate(R.layout.success_toask, null);
		   }
		   Toast toast=Toast.makeText(context,null,
					Toast.LENGTH_LONG);
			toast.setView(toaskView);
			((TextView)toaskView.findViewById(R.id.toaskMessage)).setText(message);
			toast.show();
	  }
	  public static void doShowProgressDialog(final Activity context,int message){
		  LayoutInflater inflater=LayoutInflater.from(context);
		  View progresskView=inflater.inflate(R.layout.progress_dialog, null);
		  ((TextView)progresskView.findViewById(R.id.progressMessage)).setText(message);
		  progress=ProgressDialog.show(context, null,null,true);
		  progress.setContentView(progresskView);
		  animation=(AnimationDrawable) ((ImageView)progresskView.findViewById(R.id.progressImage)).getBackground();
		  Timer animation_timer = new Timer();
		  animation_timer.schedule(new AnimationTimer(), 100);
		  progress.show();
	   }
	  
	  public static void doDimssProgressDialog(){
		  if(null!=progress){
			 if( progress.isShowing()){
				 progress.dismiss();
			 }
		  }
	  }
	  private static class AnimationTimer extends TimerTask {  
		  
	        public void run() {  
	            animation.start();  
	            this.cancel();  
	        }  
	          
	    }  
}
